package io.gitee.xyuesheng.day06;

import org.junit.Test;

import java.util.Map;
import java.util.TreeMap;

public class HomeworkLetters {
    @Test
    public void testCountLetter() {
        String s = "beyond your current AbiliTy";
        System.out.println(countLetters(s));
    }

    public Map<Character, Integer> countLetters(String s) {
        Map<Character, Integer> map = new TreeMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            int asc = Integer.valueOf(c);
            if (asc < 65 || (asc > 90 && asc < 97) || asc > 122) {
                continue;
            }
            if (asc <= 90) {
                c = (char) (c + 32);
            }
            if (map.containsKey(c)) {
                map.put(c, map.get(c) + 1);
            } else {
                map.put(c, 1);
            }
        }
        return map;
    }

}
